package com.xieyingwangluo.yxpart.api;

import com.xieyingwangluo.yxpart.bean.Result;
import com.xieyingwangluo.yxpart.entity.MerchantModel;
import com.xieyingwangluo.yxpart.logic.MerchantLogic;
import com.xieyingwangluo.yxpart.service.MerchantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@CrossOrigin
@Api(tags = "merchant接口")
@Controller
@RequestMapping(value = "/api/v1/merchant")
public class MerchantBaseRest extends BaseRest {
    @Autowired
    private MerchantLogic merchantLogic;

    //商户的登陆:昵称(name),密码(pwd)
    @ApiOperation(value = "商户的登录", notes = "商户的登录", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tel", value = "电话", required = false, dataType = "String", paramType = "query", defaultValue = "18331977512"),
            @ApiImplicitParam(name = "pwd", value = "密码", required = false, dataType = "String", paramType = "query", defaultValue = "12345678")
    })
    @ResponseBody
    @GetMapping(value = "/checklogin")
    public Result checklogin(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                             HttpSession session,
                             @RequestParam("tel") String tel,
                             @RequestParam("pwd") String pwd
    ) {
        return merchantLogic.checklogin(session, tel, pwd);
    }

    //商户的退出
    @ApiOperation(value = "商户的退出", notes = "商户的退出", produces = "application/json")
    @ApiImplicitParams({
    })
    @ResponseBody
    @GetMapping(value = "/outlogin")
    public Result outlogin(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                           HttpSession session
    ) {
        return merchantLogic.outlogin(session);
    }

    //商户添加:电话(tel),密码(pwd),昵称(name),头像(head_img),积分(intg),状态(state),会员(vip)
    @ApiOperation(value = "添加商户信息", notes = "添加商户信息", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noid", value = "商户id", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "tel", value = "电话", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pwd", value = "密码", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "昵称", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "head_img", value = "头像", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "intg", value = "积分", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "vip", value = "会员", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "create_time", value = "注册时间", required = false, dataType = "String", paramType = "query")
            })
    @ResponseBody
    @PostMapping(value = "/add")
    public Result add(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                      MerchantModel merchantModel
    ) {
        return merchantLogic.add(merchantModel);
    }

    //商户信息修改:商户信息编号id(noid)
    @ApiOperation(value = "商户信息修改", notes = "商户信息修改", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noid", value = "商户id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "tel", value = "电话", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pwd", value = "密码", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "昵称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "head_img", value = "头像", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "intg", value = "积分", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "vip", value = "会员", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "create_time", value = "注册时间", required = false, dataType = "String", paramType = "query")
    })
    @ResponseBody
    @PutMapping(value = "/upd")
    public Result upd(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                      MerchantModel merchantModel
    ) {
        return merchantLogic.upd(merchantModel);
    }

    //商户信息展示：商户编号(noid)
    @ApiOperation(value = "显示商户信息", notes = "显示商户信息", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noid", value = "商户信息编号id", required = true, dataType = "String", paramType = "query", defaultValue = "9dab861f-a73f-11e8-b52f-000c2984c921")
    })
    @ResponseBody
    @GetMapping(value = "/selO")
    public Result selO(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                       @RequestParam("noid") String noid
    ) {
        return merchantLogic.selO(noid);
    }
}
